package com.example.mapper;

import com.example.pojo.Dept;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * DeptMapper 类的描述信息
 *
 * @author 12427
 * @since 2025/6/3 10:07
 */
@Mapper//交给容器
public interface DeptMapper {
    /**
     * 字段和数据库字段不一致
     * 手动封装
     */
//    @Results({
//            @Result(column = "create_time",property = "createTime"),
//            @Result(column = "update_time",property = "updateTime"),
//    })

//  方法2  起别名
//    @Select("SELECT id,name,create_time createTime,update_time updateTime FROM dept ORDER BY  update_time desc")
//    List<Dept> findAll();

//终结 仔 yml 开启 映射别名  要求字段 (aaa_time -> aaaTime)
    @Select("SELECT id,name,create_time,update_time FROM dept ORDER BY  update_time desc")
    List<Dept> findAll();

    @Delete("delete from dept where id=#{id}")
    void deleteById(int id);

    @Insert("insert into dept(name,create_time,update_time) value (#{name},#{createTime},#{updateTime})")
    void insert(Dept dept);

    /**
     * 根据id查询
     */
    @Select("select  id, name, create_time, update_time from dept where id =#{id}")
    Dept findId(Integer id);

    /*修改*/
    @Update("update dept set name=#{name},update_time=#{updateTime} where id = #{id}")
    void update(Dept dept);
}
